Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / app / src / main / java / com / geeksville / mesh / util / Exceptions.kt

Displaying Raw • Download

app/src/main/java/com/geeksville/mesh/util/Exceptions.kt 78274c792318331b11ab64cd28e58e829875b8c2 (78274c79) Text, 2.59 KB

T8b949e/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

Tff7b72package T7ee787com.geeksville.mesh.util

Tff7b72import T7ee787android.os.RemoteException
Tff7b72import T7ee787android.util.Log
Tff7b72import T7ee787timber.log.Timber

Tff7b72object T56d364Exceptions Tb4b4b4{
T8b949e// / Set in Application.onCreate
Tff7b72var Te6edf3reporterTb4b4b4: Tb4b4b4(Tb4b4b4(Te6edf3ThrowableTb4b4b4, Tffa657String?Tb4b4b4, Tffa657String?Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4)Tff7b72? Tff7b72= Tff7b72null

T8b949e/**
* Report an exception to our analytics provider (if installed - otherwise just log)
*
* After reporting return
*/
Tff7b72fun Td2a8ffreportTb4b4b4(Te6edf3exceptionTb4b4b4: Te6edf3ThrowableTb4b4b4, Te6edf3tagTb4b4b4: Tffa657String? Tff7b72= Tff7b72nullTb4b4b4, Te6edf3messageTb4b4b4: Tffa657String? Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
Te6edf3TimberTb4b4b4.Te6edf3eTb4b4b4(
Te6edf3exceptionTb4b4b4,
Ta5d6ff"Ta5d6ffExceptions.report: Tffd700$Te6edf3tagTa5d6ff Tffd700$Te6edf3messageTa5d6ff"Tb4b4b4,
Tb4b4b4) T8b949e// print the message to the log _before_ telling the crash reporter
Te6edf3reporterTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3r Tff7b72-Tff7b72> Te6edf3rTb4b4b4(Te6edf3exceptionTb4b4b4, Te6edf3tagTb4b4b4, Te6edf3messageTb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* This wraps (and discards) exceptions, but first it reports them to our bug tracking system and prints a message to
* the log.
*/
Tff7b72fun Td2a8ffexceptionReporterTb4b4b4(Te6edf3innerTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3innerTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3exTb4b4b4: Te6edf3ThrowableTb4b4b4) Tb4b4b4{
T8b949e// DO NOT THROW users expect we have fully handled/discarded the exception
Te6edf3ExceptionsTb4b4b4.Te6edf3reportTb4b4b4(Te6edf3exTb4b4b4, Ta5d6ff"Ta5d6ffexceptionReporterTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffUncaught ExceptionTa5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e/** This wraps (and discards) exceptions, but it does output a log message */
Tff7b72fun Td2a8ffignoreExceptionTb4b4b4(Te6edf3silentTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72falseTb4b4b4, Te6edf3innerTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3innerTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3exTb4b4b4: Te6edf3ThrowableTb4b4b4) Tb4b4b4{
T8b949e// DO NOT THROW users expect we have fully handled/discarded the exception
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3silentTb4b4b4) Te6edf3TimberTb4b4b4.Te6edf3eTb4b4b4(Ta5d6ff"Ta5d6ffignoring exceptionTa5d6ff"Tb4b4b4, Te6edf3exTb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e// / Convert any exceptions in this service call into a RemoteException that the client can
T8b949e// / then handle
Tff7b72fun Tff7b72<Te6edf3TTff7b72> Td2a8fftoRemoteExceptionsTb4b4b4(Te6edf3innerTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Te6edf3TTb4b4b4)Tb4b4b4: Te6edf3T Tff7b72= Tff7b72try Tb4b4b4{
Te6edf3innerTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3exTb4b4b4: Te6edf3ThrowableTb4b4b4) Tb4b4b4{
Te6edf3LogTb4b4b4.Te6edf3eTb4b4b4(Ta5d6ff"Ta5d6fftoRemoteExceptionsTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffUncaught exception, returning to remote clientTa5d6ff"Tb4b4b4, Te6edf3exTb4b4b4)
Tff7b72when Tb4b4b4(Te6edf3exTb4b4b4) Tb4b4b4{ T8b949e// don't double wrap remote exceptions
Tff7b72is Te6edf3RemoteException Tff7b72-Tff7b72> Tff7b72throw Te6edf3ex
Tff7b72else Tff7b72-Tff7b72> Tff7b72throw Te6edf3RemoteExceptionTb4b4b4(Te6edf3exTb4b4b4.Te6edf3messageTb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.04s